//
//  SelectedDomainManager.swift
//  SmallParts
//
//  Created by 航汇聚 on 2019/12/23.
//  Copyright © 2019 BellaZhou. All rights reserved.
//

import UIKit

class SelectedDomainManager: NSObject {
    enum SelectedDoaminHandleState {
        case delete
        case add
        case search
    }
    static let shared: SelectedDomainManager = {
       return SelectedDomainManager()
    }()
    private lazy var localSelectedDomainPath: URL = {
        let manager = FileManager.default
        var filePath = manager.urls(for: FileManager.SearchPathDirectory.documentDirectory, in: FileManager.SearchPathDomainMask.userDomainMask).first
        filePath!.appendPathComponent("localSelectedDomainData.archive")
        return filePath!
        }()
    func handleDomainData(with state: SelectedDoaminHandleState, selectedDomains: [DomainItemObject]) -> Bool {
        switch state {
        case .add:
            let dataWriter = try? JSONEncoder().encode(selectedDomains)
            do {
                try dataWriter?.write(to: localSelectedDomainPath)
            } catch  {
                print("保存到本地文件失败！")
            }
            break
        case .delete:
            break
        case .search:
            break
        }
        return false
    }
}
